import axios from 'axios';
import { API_ROOT } from '../config.jsx';

export const USER_REGISTER = 'USER_REGISTER';
export const USER_GET_USERINFO = 'USER_GET_USERINFO';
export const USER_GET_HOSPITAL = 'USER_GET_HOSPITAL';

export function getUserInfo(openid) {
    axios.defaults.headers.post['Content-Type'] = 'application/json';
    const userInfo = axios.get(`${API_ROOT}/wechatapi/UserInfo/${openid}`);
    return {
        type: USER_GET_USERINFO,
        payload: userInfo
    };
}

export function register(userinfo) {
    axios.defaults.headers.post['Content-Type'] = 'application/json';
    const result = axios.post(`${API_ROOT}/WechatApi/Register`, userinfo);

    return {
        type: USER_REGISTER,
        payload: result
    };
}

export function getHospital(province, city) {
    const result = axios.post(`${API_ROOT}/WechatApi/hospitals`,{province:province,city:city});

    return {
        type: USER_GET_HOSPITAL,
        payload: result
    };
}